import { platformOrderListColumns } from './platformOrderList.config.js'
import search from './../search/search.js';
import { refundOutStockDetailList, shopRefundOutStockCancel, shopRefundOutStockConfirm } from '@/api/shop/stock/outstockList.js'

export default {
    name: "platformOrderList",
    mixins: [search],
    data() {
        return {
            platformOrderListColumns,
            loading: false,
            loadData: [],
            page: {
                current: 1,
                total: 0,
                size: 10
            },
            selectedRows: [],//选中的数组
            selectedRowKeys: [],  //选中的数组
            number: 0,
            btn: [
                {
                    title: "新增退货出库单",
                    isShow: true
                },
            ]
        }
    },
    filters: {
        status(val) {
            let obj = ''
            switch (val) {
                case '00':
                    obj = '待出库'
                    break;
                case '01':
                    obj = '部分出库'
                    break;
                case '02':
                    obj = '已出库'
                    break;
                case '03':
                    obj = '已取消'
                    break;
                default:
                    obj = '已完成'
            }
            return obj
        },
        billStatus(val) {
            let obj = ''
            switch (val) {
                case '00':
                    obj = '采购入库'
                    break;
                case '01':
                    obj = '采购退货入库'
                    break;
                case '02':
                    obj = '配送出库'
                    break;
                case '03':
                    obj = '门店退货入库'
                    break;
                case '04':
                    obj = '门店销售'
                    break;
                case '05':
                    obj = '门店退货'
                    break;
                case '06':
                    obj = '门店盘盈入库'
                    break;
                case '07':
                    obj = '门店盘亏出库'
                    break;
                case '08':
                    obj = '平台推送到门店入库'
                    break;
                case '09':
                    obj = '门店主动退货出库'
                    break;
                default:
                    obj = ''
            }
            return obj
        },

    },
    methods: {
        getList(searchForm, page) {
            if (searchForm) {
                console.log(searchForm)
            }
            if (page) {
                this.page.current = page
            }
            refundOutStockDetailList(Object.assign({ deptId: this.$store.getters.userInfo.sysUser.deptId, tenantId: this.$store.getters.userInfo.sysUser.tenantId }, searchForm ? searchForm : {}, this.page)).then(val => {
                let data = val.data.records
                this.page = {
                    current: val.data.current,
                    total: val.data.total,
                    size: val.data.size,
                }
                this.loadData = data
                this.$emit("trigger")
            })
        },
        onShowSizeChange(current, size) {
            console.log(current, size)
            this.page.current = current
            this.page.size = size
            this.getList()
        },
        onSelectChange(selectedRowKeys, selectedRows) {
            this.selectedRowKeys = selectedRowKeys
            this.selectedRows = selectedRows;
            this.number = this.selectedRows.length
        },
        // 清空选中项
        clearSelection() {
            this.selectedRowKeys = []
            this.number = 0
        },
        handler(index) {
            if (index == 0) {
                this.platformOrderList()
            }
        },
        // 新增出库单
        platformOrderList() {
            this.$router.push({ path: "/shop/stock/outstockList/addOrder" })
        },
        chuKuClick(item) {
            var that = this
            this.$confirm({
                title: '确定要出库出库单号为' + item.outStockId + '吗？',
                onOk() {
                    shopRefundOutStockConfirm({ outStockId: item.outStockId }).then(val => {
                        that.getList()
                        that.$message.success('出库成功')
                    })
                },
                class: 'test',
            });
        },
        details(item) {
            this.$router.push({
                path: "/shop/stock/outstockList/inDetails", query: {
                    outStockId: item.outStockId,
                    status: item.status
                }
            })
        },
        zuoFei(item) {
            var that = this
            this.$confirm({
                title: '确定要作废出库单号为' + item.outStockId + '吗？',
                onOk() {
                    shopRefundOutStockCancel({ outStockId: item.outStockId }).then(val => {
                        that.getList()
                        that.$message.success('作废成功')
                    })
                },
                class: 'test',
            });
        }
    }

} 